import 'dart:async';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class Video_ extends StatefulWidget {
  const Video_({Key? key}) : super(key: key);

  @override
  State<Video_> createState() => _Video_State();
}

class _Video_State extends State<Video_> {
  late VideoPlayerController Videokongzhiqi;
  late Future<void> chushihuaVideo;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    Videokongzhiqi = VideoPlayerController.networkUrl(
      Uri.parse(
        'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
      ),
    );
    chushihuaVideo = Videokongzhiqi.initialize();
  }
  @override
  void dispose() {
    // TODO: implement dispose
    Videokongzhiqi.dispose();
    super.dispose();
  }
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.pink,
        title: Text('VidoPlayerController'),
        centerTitle: true,
      ),
      body: Stack(
        children: [
          Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: PageView(
              scrollDirection: Axis.vertical,
              children: [
                Container(
                  color: Colors.black,
                  width: MediaQuery.of(context).size.width,
                  height: MediaQuery.of(context).size.height,
                  child: VideoPlayer(Videokongzhiqi),
                  // child: FutureBuilder(
                  //   future: chushihuaVideo,
                  //   builder: (context,sp){
                  //     if(sp.connectionState == ConnectionState.done){
                  //       return AspectRatio(aspectRatio: Videokongzhiqi.value.aspectRatio,
                  //         child: VideoPlayer(Videokongzhiqi),
                  //       );
                  //     }else{
                  //       return Center(
                  //         child: CircularProgressIndicator(),
                  //       );
                  //     }
                  //   },
                  // ),
                ),
                Container(
                  width: MediaQuery.of(context).size.width,
                  height: MediaQuery.of(context).size.height,
                  color: Colors.black,
                ),
              ],
            ),
          ),
          Positioned(
            left: MediaQuery.of(context).size.width/2.3,
            top: MediaQuery.of(context).size.height/1.5,
            child: Container(
              child: FloatingActionButton(
                onPressed: (){
                  setState(() {
                    if(Videokongzhiqi.value.isPlaying){
                      Videokongzhiqi.pause();
                    }else{
                      Videokongzhiqi.play();
                    }
                  });
                },
                child: Icon(Videokongzhiqi.value.isPlaying?Icons.pause:Icons.play_arrow),
              ),
            ),
          )
        ],
      )
    );
  }
}

